package com.my.aslife.module.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    private String code;
    private T data;
    private String msg;
    private Integer total;

    public static <T> ResponseResult<T> ok(){
        ResponseResult<T> responseResult = new ResponseResult<>("200","ok");
        return responseResult;
    }

    public static <T> ResponseResult<T> ok(T data){
        ResponseResult<T> responseResult = new ResponseResult<>("200","ok");
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult<T> ok(T data, Integer total){
        ResponseResult<T> responseResult = new ResponseResult<>("200","ok");
        responseResult.setTotal(total);
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult<T> failed(String code, String msg){

        return new ResponseResult<T>(code, msg);
    }

    public static <T> ResponseResult<T> failed(ErrorCode errorCode){
        return new ResponseResult<T>(errorCode.getCode(), errorCode.getMessage());
    }

    public ResponseResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
